package com.llyb.exception;

import com.llyb.result.ResultData;
import com.llyb.result.ReturnCodeEnum;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResultData<String> businessException(BusinessException e,HttpServletRequest request){
        log.info("局部异常信息：{},请求是{}",e.getMessage(),request.getRequestURL());
        return ResultData.fail(e.getCode(),e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public ResultData<String> exception(Exception e){

        log.info("全局异常信息：{}",e.getMessage());
        return ResultData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());

    }

}
